package com.codemonkey.lq.qd.facotry.config;

import java.util.EventObject;

import com.codemonkey.lq.qd.ServiceContext;

/**仿ApplicationEvent(org.springframework.context.ApplicationEvent)
 * 仿Spring的package结构,将其放在顶级目录
 * @author LQ
 *
 */
public abstract class ExecutionEvent extends EventObject {

	private static final long serialVersionUID = 910626L;

	private final ServiceContext sContext;

	private final boolean isSuc;
	
	private Exception error;

	//直接抄自Spring的ApplicationEvent
	/** System time when the event happened */
	private final long timestamp;

	protected ExecutionEvent(boolean isSuccess, Object source, ServiceContext sc) {
		super(source);

		this.timestamp = System.currentTimeMillis();
		this.sContext = sc;
		this.isSuc = isSuccess;
	}

	/**
	 * Return the system time in milliseconds when the event happened.
	 */
	public final long getTimestamp() {
		return this.timestamp;
	}

	public ServiceContext getSContext() {
		return sContext;
	}

	public boolean isSuccess() {
		return isSuc;
	}

	//------------------------------ 本次执行失败时,失败的原因 ---------------------------------
	public Exception getError() {
		return error;
	}

	public void setError(Exception error) {
		this.error = error;
	}
}
